﻿namespace Zhaoxi.NET7Demo
{
    public static class MiddleExtend
    { 
        public static void UseMiddleware01(this WebApplication app)
        {
            Func<RequestDelegate, RequestDelegate> middleweare01 = next =>
                 async context =>
                 {
                     await context.Response.WriteAsync("<p>this is middleware001 Strat</p>");
                     await next.Invoke(context);  //这句话的执行 执行功的是下一个中间件的内容
                     await context.Response.WriteAsync("<p>this is middleware001 End</p>");
                 };
            ((IApplicationBuilder)app).Use(middleweare01);  //开始委托的精彩内容~
        }

        public static void UseMiddleware02(this WebApplication app)
        {
            Func<RequestDelegate, RequestDelegate> middleweare02 = next =>
                async context =>
                {
                    await context.Response.WriteAsync("<p>this is middleware002 Strat</p>");
                    await next.Invoke(context); //这句话的执行 执行功的是下一个中间件的内容
                    await context.Response.WriteAsync("<p>this is middleware002 End</p>");
                };
            ((IApplicationBuilder)app).Use(middleweare02);  //开始委托的精彩内容~
        }

        public static void UseMiddleware03(this WebApplication app)
        {
            Func<RequestDelegate, RequestDelegate> middleware03 = next =>
                    async context =>
                    {
                        await context.Response.WriteAsync("<p>this is middleware003 Strat</p>");
                        await next.Invoke(context); //这句话的执行 执行功的是下一个中间件的内容 
                        await context.Response.WriteAsync("<p>this is middleware003 End</p>");
                    };

            ((IApplicationBuilder)app).Use(middleware03);  //开始委托的精彩内容~
        }
    }
}
